﻿// Copyright (c) 2014 Morten Bakkedal
// This code is published under the MIT License.

using System;
using System.Collections.Generic;
using System.Reflection;

namespace FuncLib.DualFunctions.Compilation
{
	public class DualEvaluator
	{
		private object instance;
		private MethodInfo methodInfo;
		private string identifier;

		public DualEvaluator(object instance, MethodInfo methodInfo, string identifier)
		{
			this.instance = instance;
			this.methodInfo = methodInfo;
			this.identifier = identifier;
		}

		public string Identifier
		{
			get
			{
				return identifier;
			}
		}

		public void Value(Dictionary<int, double> x, Dictionary<string, double> y)
		{
			try
			{
				methodInfo.Invoke(instance, new object[] { x, y });
			}
			catch (TargetInvocationException e)
			{
				throw new Exception("TargetInvocationException: " + e.InnerException.Message); // FIXME
			}
		}
	}
}
